package com.dingup.mock.bean.writing;


import com.dingup.mock.enums.WritingQuestionTypeEnum;
import com.google.gson.Gson;

import java.util.HashMap;

import static com.dingup.mock.util.ConstUtil.*;


/**
 * Created by yanggavin on 16/4/26.
 *
 * 注:具体的问题xml数据结构
 <root>
    <type>integrated/independent</type>
    <integrated>
        <reading>
            <content>阅读部分原文</content>
        </reading>
        <listening>
            <pic>听力部分图片URL</pic>
            <audio>听力部分音频URL</audio>
        </listening>
    </integrated>
    <question><p>问题第一段</p><p>问题第二段</p><p>问题第三段</p></question>
 </root>
 */
public class WritingQuestionXml {
    private WritingQuestionTypeEnum type;
    private HashMap<String, HashMap<String, String>> integrated;
    private String question;

    public WritingQuestionTypeEnum getType() {
        return type;
    }

    public void setType(WritingQuestionTypeEnum type) {
        this.type = type;
    }

    public HashMap<String, HashMap<String, String>> getIntegrated() {
        return integrated;
    }

    public void setIntegrated(HashMap<String, HashMap<String, String>> integrated) {
        this.integrated = integrated;
    }

    public String getQuestion() {
        return question;
    }

    public void setQuestion(String question) {
        this.question = question;
    }

    public String toXmlString(){
        StringBuilder xmlBuilder = new StringBuilder();
        xmlBuilder.append("<root>");
        xmlBuilder.append(String.format("<type>%s</type>", type.getCode()));
        xmlBuilder.append("<integrated>");
        xmlBuilder.append(String.format("<reading><content>%s</content></reading>",
                integrated.get(XML_NODE_NAME_READING).get(XML_NODE_NAME_CONTENT)));
        xmlBuilder.append(String.format("<listening><pic>%s</pic><audio>%s</audio></listening>",
                integrated.get(XML_NODE_NAME_LISTENING).get(XML_NODE_NAME_PIC), integrated.get(XML_NODE_NAME_LISTENING).get(XML_NODE_NAME_AUDIO)));
        xmlBuilder.append("</integrated>");
        xmlBuilder.append(String.format("<question>%s</question>", question));
        xmlBuilder.append("</root>");
        return xmlBuilder.toString();
    }

    public String toJsonString(){
        Gson gson = new Gson();
        return gson.toJson(this);
    }
}
